
import java.io.IOException;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Andik Taufiq
 * Represents the board of puzzle
 * March, 27 2010 - Bandung, Indonesia
 */
public class Board {
    public Tile[] tiles;
    private static int NB_TILES = 9;
    public int[] state;
    public int x, y, xTilesRef, yTilesRef;
    public Image boardImg;
    public Board(int[] state, int x, int y) {
        this.state = state;
        this.x = x;
        this.y = y;
        try {
            boardImg		= Image.createImage("/board.png");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        xTilesRef = x - (boardImg.getWidth() / 2) + 9;
        yTilesRef = y - (boardImg.getHeight() / 2) + 9;
        tiles = new Tile[9];
        for (int i = 0; i < NB_TILES; i++) {
            tiles[i] = new Tile(this, this.state[i], i);
        }
    }

    public void paint(Graphics g) {
        g.drawImage(boardImg, x, y, Graphics.VCENTER | Graphics.HCENTER);
        for (int i = 0; i < NB_TILES; i++) {
            tiles[i].type = state[i];
            tiles[i].position = i;
            tiles[i].paint(g);
        }
    }
}
